package edu.nus.mtech.sem1.ca.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;


/**
 * Provides utility methods to close inputStream and outputStream without any noise of exception handling boilerplate in the host code.
 * 
 * Ssssh.. Silence please 
 *
 */
public class IOUtils {
	
	public static void closeQuietly(InputStream inputStream){
		try {
			if (inputStream!=null){
				inputStream.close();
				inputStream=null;
			}
		} catch (IOException e) {
			//Ignoring error
			e.printStackTrace();
		}
	}

	public static void closeQuietly(Reader reader) {
		try {
			if (reader!=null){
				reader.close();
				reader=null;
			}
		} catch (IOException e) {
			//Ignoring error
			e.printStackTrace();
		}
	}

	public static void closeQuietly(OutputStream outputStream){
		try {
			if (outputStream!=null){
				outputStream.close();
				outputStream=null;
			}
		} catch (IOException e) {
			//Ignoring error
			e.printStackTrace();
		}
	}

	public static void closeQuietly(Writer writer) {
		try {
			if (writer!=null){
				writer.close();
				writer=null;
			}
		} catch (IOException e) {
			//Ignoring error
			e.printStackTrace();
		}
	}
}
